package com.xungou.resource.controller;

import com.xungou.resource.service.IResourceService;
import com.xungou.utils.FileUtil;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.Map;

@Controller
@RequestMapping("/resource")
public class ResourceController {
    @Resource
    private IResourceService resourceService;

    @RequestMapping("/download")
    public ResponseEntity<byte[]> download(@RequestParam Map<String, String> params) throws IOException {
        return FileUtil.download(resourceService.selectByPrimaryKey(Integer.parseInt(params.get("id"))));
    }
}